﻿Ext.define('Kwan.ex.Date', {
    extend: 'Ext.DatePicker',
    alias: 'widget.Kwan.ex.Date',
    format: 'Y年m月d日',
    emptyText: '请选择日期 ...',
    vtype: 'daterange',
    initComponent: function () {
        Ext.apply(Ext.form.field.VTypes, {
            daterange: function (val, field) {
                var date = field.parseDate(val);

                if (!date) {
                    return false;
                }
                if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
                    var start = Ext.getCmp(field.startDateField);
                    start.setMaxValue(date);
                    start.validate();
                    this.dateRangeMax = date;
                }
                else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
                    var end = Ext.getCmp(field.endDateField);
                    end.setMinValue(date);
                    end.validate();
                    this.dateRangeMin = date;
                }

                return true;
            },
            daterangeText: 'Start date must be less than end date'
        });
        this.callParent(arguments);
    }
});